﻿using System;
using System.Configuration;
using mojoPortal.Net;
using mojoPortal.Web;
using Resources;
using mojoPortal.Web.Framework;
using System.Collections;
using mojoPortal.Business;
using ud_gSDMS.Code_Service;
using mojoPortal.Business.WebHelpers;
using System.IO;
using Brettle.Web.NeatUpload;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI;
namespace ud_gSDMS.Member
{
    public partial class UpdateSiblings : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        private string id;
        private SiteUser _siteUser;
        protected String cacheDependencyKey;
        DBQLNS _respository=new DBQLNS();
        
        void Page_Load(object sender, EventArgs e)
        {
            _siteUser = SiteUtils.GetCurrentSiteUser();
            if (_siteUser == null)
            {
                WebUtils.SetupRedirect(this, SiteRoot + "/AccessDenied.aspx");
            }

            if (!Page.IsPostBack)
            {
                PopulateLabels();
                PopulateControls();
            }
        }
        private void PopulateLabels()
        {
            leftMenuItem.CurrentSite = Request.RawUrl;
            SiblingsTest child1 = new SiblingsTest("Đinh Khắc Sơn", "", "1960", "Sỹ quan QĐND", "huyện đội Đức Thọ, cư trú tại xã Đức Lâm, huyện Đức Thọ");
            SiblingsTest child2 = new SiblingsTest("Đinh Xuân Lâm", "", "1963", "Bác Sĩ", "12 A1 chung cư An Lộc, Q. Gò Vấp, Tp. HCM");
            SiblingsTest child3 = new SiblingsTest("Đinh Khắc Hào", "", "1968", "Công Nhân", "Công ty truyền tải điện Cần Thơ (đã chết)");
            List<SiblingsTest> lst = new List<SiblingsTest>();
            lst.Add(child1);
            lst.Add(child2);
            Session["Si"] = lst;
        }
        private void BindData()
        {
            gvChildInfo.DataSource = Session["Si"];
            gvChildInfo.DataBind();
        }

        private void PopulateControls()
        {
            BindData();
        }
        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            AllowSkinOverride = true;
            base.OnPreInit(e);
            Load += Page_Load;
        }

        protected override void OnInit(EventArgs e)
        {
            LoadParams();
            LoadPanels();
            base.OnInit(e);
            SuppressPageMenu();
        }

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, moduleId);
            id = WebUtils.ParseStringFromQueryString("id", id);
            cacheDependencyKey = "Module-" + moduleId.ToInvariantString();
        }

        private void LoadPanels()
        {
            bool showLeftColumnAdmin = ConfigHelper.GetBoolProperty("ShowLeftColumnAdmin", false);
            bool showRightColumnAdmin = ConfigHelper.GetBoolProperty("ShowRightColumnAdmin", false);
            bool showTopColumnAdmin = ConfigHelper.GetBoolProperty("ShowTopColumnAdmin", false);
            bool showBottomColumnAdmin = ConfigHelper.GetBoolProperty("ShowBottomColumnAdmin", false);
            int showCenterColumnAdmin = ConfigHelper.GetIntProperty("ShowCenterColumnAdmin", 0);
            LoadSideContent(showLeftColumnAdmin, showRightColumnAdmin, showTopColumnAdmin, showBottomColumnAdmin, showCenterColumnAdmin);
        }
        #endregion

        protected void gvChildInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvChildInfo.EditIndex = e.NewEditIndex;
            BindData();
        }

        protected void gvChildInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void gvChildInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            List<SiblingsTest> l = (List<SiblingsTest>)Session["Si"];
            TextBox txt_hoten = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt1");
            TextBox txt_nu = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt2");
            TextBox txt_ngaysinh = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt3");
            TextBox txt_nghenghiep = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt4");
            TextBox txt_noio = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt5");

            SiblingsTest newsiblings = new SiblingsTest(txt_hoten.Text, txt_nu.Text, txt_ngaysinh.Text, txt_nghenghiep.Text, txt_noio.Text);
            l[e.RowIndex] = newsiblings;
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void gvChildInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            List<SiblingsTest> l = (List<SiblingsTest>)Session["Si"];
            l.RemoveAt(e.RowIndex);
            BindData();
        }
    }

    public class SiblingsTest
    {
        public string HoTen {get ; set;}
        public string Nu { get; set; }
        public string NgaySinh { get; set; }
        public string NgheNghiep { get; set; }
        public string NoiO { get; set; }
        public SiblingsTest(string hoten, string nu, string ngaysinh, string nghenghiep, string noio)
        {
            this.HoTen = hoten;
            this.Nu = nu;
            this.NgaySinh = ngaysinh;
            this.NgheNghiep = nghenghiep;
            this.NoiO = noio;
        }
    }

    
}